Telegram Group & Telegram Channel
🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/cppproglib/5707
Create:
Last Update:

🤓 Как использовать концепты C++20 для создания надежного кода

Устали от непонятных ошибок шаблонов? Концепты спешат на помощь.

//  Старый подход без концептов
template<typename T>
T max_value(const std::vector<T>& values) {
// Ошибка будет обнаружена только при инстанциации шаблона
return *std::max_element(values.begin(), values.end());
}

// Современный подход с концептами
template<typename T>
requires std::totally_ordered<T>
T max_value(const std::vector<T>& values) {
return *std::max_element(values.begin(), values.end());
}

// Еще короче с auto
auto max_value(const std::vector<std::totally_ordered auto>& values) {
return *std::max_element(values.begin(), values.end());
}


❗️Преимущества:

- Более понятные сообщения об ошибках
- Документирование требований в коде
- Перегрузка на основе свойств типов

Встроенные концепты: std::integral, std::floating_point, std::copyable, std::same_as и другие.

Библиотека C/C++ разработчика
#буст

BY Библиотека C/C++ разработчика | cpp, boost, qt


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/cppproglib/5707

View MORE
Open in Telegram


Библиотека C C разработчика | cpp boost qt Telegram | DID YOU KNOW?

Date: |

Telegram Be The Next Best SPAC

I have no inside knowledge of a potential stock listing of the popular anti-Whatsapp messaging app, Telegram. But I know this much, judging by most people I talk to, especially crypto investors, if Telegram ever went public, people would gobble it up. I know I would. I’m waiting for it. So is Sergei Sergienko, who claims he owns $800,000 of Telegram’s pre-initial coin offering (ICO) tokens. “If Telegram does a SPAC IPO, there would be demand for this issue. It would probably outstrip the interest we saw during the ICO. Why? Because as of right now Telegram looks like a liberal application that can accept anyone - right after WhatsApp and others have turn on the censorship,” he says.

Библиотека C C разработчика | cpp boost qt from tr


Telegram Библиотека C/C++ разработчика | cpp, boost, qt
FROM USA